package com.haiou.model;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Serializable;

/**
 * @author wang fei
 * @date 2020-10-15 15:13
 *  返回数据类
 */
@ApiModel("返回类型")
public class ResultModel<T> implements Serializable {

    private static final Logger log = LoggerFactory.getLogger(ResultModel.class);

    @ApiModelProperty(value = "标识码", name = "code")
    private Integer code;

    @ApiModelProperty(value = "数据", name = "data")
    private T data;

    @ApiModelProperty("返回信息")
    private String message;

    public ResultModel(){
        code = 200;
        message = "成功";
    }

    public ResultModel(String message){
        this.code = 500;
        this.message = message;
    }

    public ResultModel(T t){
        this.code = 200;
        this.message = "成功";
        this.data = t;
    }

    /**
     * 成功返回，[带参数]
     */
    public static <T> ResultModel success(T t){
        return new ResultModel(t);
    }

    /**
     * 成功返回不带参数
     */
    public static ResultModel success(){
        return new ResultModel();
    }

    /**
     * 错误返回
     */
    public static ResultModel fail(String message){
        return new ResultModel(message);
    }

    public static Logger getLog() {
        return log;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
